package com.example.cslp.mapper;

import com.example.cslp.pojo.entity.Course;
import com.example.cslp.pojo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    public User findCourseById(int CourseId);
    //签到积分+2
    @Update("update users set points=points+2 ,lastdate=#{lastdate} where name=#{name}")
    Boolean point(User user);

    //登录，返回user是为了检查找到没有
    @Select("select * from users where name=#{name}")
    User login(String name);

    //注册
    @Insert("insert into users(name,password,register_time,nickname,mail,phone)" +
            " values (#{name},#{password},#{registerTime},#{nickname},#{mail},#{phone})")
    Boolean register(User user);

    //主页的查询用户信息,但是不查密码
//    @Select("SELECT id, name,point,mail,status,nickname,lastdate FROM users WHERE name = #{name}")
//    User gerUserInfo(String name);
    @Select("select id, name, points, mail,status,lastdate, nickname,phone,is_admin,lastdate from users where name=#{name}")
    User getUserInfo(String name);

    //主页的编辑用户信息
//    @Update("update users set nickname=#{nickname},mail=#{mail} where id=#{id}")
//    Boolean editUser(User user);
    @Update("UPDATE users SET points=#{user.points}, mail=#{user.mail}, nickname=#{user.nickname}, phone=#{user.phone} WHERE name=#{check_name}")
    Boolean editInfo(@Param("user") User user, @Param("check_name") String check_name);

    //修改用户密码
//    @Update("update users set password=#{password} where id=#{id}")
//    Boolean editPassword(User user);
    @Update("update users set password=#{new_password} where name=#{id}")
    Boolean editPassword(@Param("new_password") String new_password, @Param("id") String id);

    //编辑账户使用状态
    @Update("update users set status=#{status} where id=#{id}")
    Boolean editStatus(User user);

    //根据id查询用户信息
    @Select("select id, name, points, mail,status,lastdate, nickname,phone,is_admin,lastdate from users where name=#{name}")
    User getUserInfoById(String id);
    //根据用户获取选课信息
//    @Select("select * from courses where id in (select course_id from record  where user_id = #{id});")
//    List<Course> getRecordByUser(User user);

//    @Select("select * from users where name = #{name} and password = #{password}")
//    User getUserByNameAndPassword(@Param("name") String name, @Param("password") String password);
//
//    @Insert("INSERT INTO users (name, password) VALUES (#{name}, #{password})")
//    void insertUser(@Param("name") String name, @Param("password") String password);
}
